
/****** Object:  StoredProcedure [usp_GetCRM_RolesByID]    Script Date: 3/17/2013 8:51:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[usp_GetCRM_RolesByID]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [usp_GetCRM_RolesByID];
GO

CREATE PROCEDURE [usp_GetCRM_RolesByID]
(
	@RoleID int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[RoleID],
		[RoleName],
		[Description]
	FROM [CRM_Roles]
	WHERE
		([RoleID] = @RoleID)

	SET @Err = @@Error

	RETURN @Err
END
GO


/****** Object:  StoredProcedure [usp_GetAllCRM_Roles]    Script Date: 3/17/2013 8:51:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[usp_GetAllCRM_Roles]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [usp_GetAllCRM_Roles];
GO

CREATE PROCEDURE [usp_GetAllCRM_Roles]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[RoleID],
		[RoleName],
		[Description]
	FROM [CRM_Roles]

	SET @Err = @@Error

	RETURN @Err
END
GO


/****** Object:  StoredProcedure [usp_UpdateCRM_Roles]    Script Date: 3/17/2013 8:51:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[usp_UpdateCRM_Roles]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [usp_UpdateCRM_Roles];
GO

CREATE PROCEDURE [usp_UpdateCRM_Roles]
(
	@RoleID int,
	@RoleName varchar(50) = NULL,
	@Description varchar(MAX) = NULL
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	UPDATE [CRM_Roles]
	SET
		[RoleName] = @RoleName,
		[Description] = @Description
	WHERE
		[RoleID] = @RoleID


	SET @Err = @@Error


	RETURN @Err
END
GO




/****** Object:  StoredProcedure [usp_InsertCRM_Roles]    Script Date: 3/17/2013 8:51:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[usp_InsertCRM_Roles]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [usp_InsertCRM_Roles];
GO

CREATE PROCEDURE [usp_InsertCRM_Roles]
(
	@RoleID int = NULL output,
	@RoleName varchar(50) = NULL,
	@Description varchar(MAX) = NULL
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	INSERT
	INTO [CRM_Roles]
	(
		[RoleName],
		[Description]
	)
	VALUES
	(
		@RoleName,
		@Description
	)

	SET @Err = @@Error

	SELECT @RoleID = SCOPE_IDENTITY()

	RETURN @Err
END
GO


/****** Object:  StoredProcedure [usp_DeleteCRM_Roles]    Script Date: 3/17/2013 8:51:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[usp_DeleteCRM_Roles]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [usp_DeleteCRM_Roles];
GO

CREATE PROCEDURE [usp_DeleteCRM_Roles]
(
	@RoleID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	DELETE
	FROM [CRM_Roles]
	WHERE
		[RoleID] = @RoleID
	SET @Err = @@Error

	RETURN @Err
END
GO

